{
 "cells": [
  {
   "cell_type": "markdown",
   "source": [
    "## 目录列表\n",
    "os.listdir(path)\n",
    "os.scandir(path)\n"
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "source": [
    "import os\n",
    "path = '~/Documents/learn-python'\n",
    "path_abs = '/Users/yulm/Documents/learn-python'\n",
    "current_path = './'\n",
    "\n",
    "# print(os.listdir(path))\n",
    "print(os.listdir(current_path))\n",
    "print(os.listdir(path_abs))  # 绝对路径\n",
    "\n",
    "# print(os.scandir(path))\n",
    "print(os.scandir(path_abs))\n",
    "for iter in os.scandir(path_abs):\n",
    "    print(iter.name)\n",
    "\n",
    "print('----')\n",
    "from pathlib import Path\n",
    "entries = Path(path_abs)\n",
    "print(entries)\n",
    "for iter in entries.iterdir():\n",
    "    print(iter.name)"
   ],
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "['dir-ops.py', 'dir-ops.ipynb']\n",
      "['README.en.md', 'crypto', 'flaskapp', 'file-dir-ops', 'webAPP', 'file_io', 'basic', 'encoding', 'README.md', 'Pipfile', 'crawl', '.gitignore', 'http', '.git', '.vscode', 'Pipfile.lock', 'package']\n",
      "<posix.ScandirIterator object at 0x7fe959c685d0>\n",
      "README.en.md\n",
      "crypto\n",
      "flaskapp\n",
      "file-dir-ops\n",
      "webAPP\n",
      "file_io\n",
      "basic\n",
      "encoding\n",
      "README.md\n",
      "Pipfile\n",
      "crawl\n",
      ".gitignore\n",
      "http\n",
      ".git\n",
      ".vscode\n",
      "Pipfile.lock\n",
      "package\n",
      "----\n",
      "/Users/yulm/Documents/learn-python\n",
      "README.en.md\n",
      "crypto\n",
      "flaskapp\n",
      "file-dir-ops\n",
      "webAPP\n",
      "file_io\n",
      "basic\n",
      "encoding\n",
      "README.md\n",
      "Pipfile\n",
      "crawl\n",
      ".gitignore\n",
      "http\n",
      ".git\n",
      ".vscode\n",
      "Pipfile.lock\n",
      "package\n"
     ]
    }
   ],
   "metadata": {}
  }
 ],
 "metadata": {
  "orig_nbformat": 4,
  "language_info": {
   "name": "python",
   "version": "3.9.7",
   "mimetype": "text/x-python",
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "pygments_lexer": "ipython3",
   "nbconvert_exporter": "python",
   "file_extension": ".py"
  },
  "kernelspec": {
   "name": "python3",
   "display_name": "Python 3.9.7 64-bit"
  },
  "interpreter": {
   "hash": "aee8b7b246df8f9039afb4144a1f6fd8d2ca17a180786b69acc140d282b71a49"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}